//
//  HuDongFunctionView.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/10.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "HuDongFunctionView.h"

@implementation HuDongFunctionView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.clipsToBounds = YES;
    
    
    [RACObserve([TT_MessageManager manager], InteractionCount) subscribeNext:^(id x) {
        if ([TT_MessageManager manager].InteractionCount > 0) {
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                self.hudongMsgBtn.badgeValue = [NSString stringWithFormat:@"%d",[TT_MessageManager manager].InteractionCount];
                self.hudongMsgBtn.badgeBGColor = [UIColor redColor];
            });

        } else {
            self.hudongMsgBtn.badgeValue = @"";
            self.hudongMsgBtn.badgeBGColor = [UIColor clearColor];
        }
    }];
    
    [self.wodetieziControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.HuDongFunctionViewBlock) {
            self.HuDongFunctionViewBlock(HuDongFunctionViewActionType_wodetiezi);
        }
    }];
    
    [self.wodetiwenControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.HuDongFunctionViewBlock) {
            self.HuDongFunctionViewBlock(HuDongFunctionViewActionType_wodetiwen);
        }
    }];
    
    [self.wodehuatiControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.HuDongFunctionViewBlock) {
            self.HuDongFunctionViewBlock(HuDongFunctionViewActionType_wodehuati);
        }
    }];
    
    [self.wodepinglunControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.HuDongFunctionViewBlock) {
            self.HuDongFunctionViewBlock(HuDongFunctionViewActionType_wodepinglun);
        }
    }];
    
    [self.hudongxiaoxiControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.HuDongFunctionViewBlock) {
            self.HuDongFunctionViewBlock(HuDongFunctionViewActionType_hudongxiaoxi);
        }
    }];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
//        [self.contentBGView pp_clipCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight radius:15];
        [self pp_clipCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight radius:15];

    });
}

- (IBAction)closeAction:(id)sender {
    if (self.HuDongFunctionViewBlock) {
        self.HuDongFunctionViewBlock(HuDongFunctionViewActionType_close);
    }
}


+(CGFloat)calculateHeight {
    return kStatusBarHeight + 20 + 20 + (TTScreenWidth-66)/2  + 30 + 18;
}

@end
